﻿<%@ Page Language="C#"  MasterPageFile="~/Views\Home\test.master" Inherits="System.Web.Mvc.ViewPage" %>


<asp:Content ContentPlaceHolderID="test" runat="server">
<script type="text/javascript">
$(document).ready(function() {
	
	var reservationDate = new Array();
	var count = 0;
	var max = $("#loan_range").html();
			$(function() {
				var dummy = $("#latest_reservation").html();
				var latest_reservation_date = new Date( dummy );
				var copy_id = $("#copy_id").val();
				
				$.post("/Book/getReservationDates",{"copy_id":  copy_id },function(data){
				$.each(data, function( i, res){
					var resDate = res.start;
					var myDate = new Date(parseInt(resDate.replace(/\/+Date\(([\d+-]+)\)\/+/, '$1')));							
					
					reservationDate.push(myDate);
					//console.log(reservationDate.length);	
					});
									
				}, "JSON");
				
				$( "#datepicker" ).datepicker({
					minDate: new Date(),
					beforeShowDay: noWeekendsOrReservationDate
				});
				
			});
			
			function noWeekendsOrReservationDate(date)
			{
		       var noWeekend = $.datepicker.noWeekends(date);
				for(var i = 0 ; i < reservationDate.length; i++)
				{
					if(date.getFullYear() == reservationDate[i].getFullYear() && date.getMonth() == reservationDate[i].getMonth() && date.getDate() == reservationDate[i].getDate() )
					{
						count = 1;
						return [false];
					}
					else if(count == max-1)
					{
						count = 0;
						return [false];
					}
					if(!noWeekend[0])
					{
						return noWeekend;
					}
					else if(count != 0)
					{
						count = count + 1;
						return [false];
					}
					
				}
				return [true];
			}
	
});
</script>
		
 			<div class="tab_container reserve">

   				   				 
   				 <div class="sub_content">RESERVE BOOK</div>
				<div class="error"></div> 
				<p>Borrowing date: <input type="text" id="datepicker"><input type="button" class="saveReservation" id="<%= Html.Encode(ViewData["copy_id"]) %>" value="Reserve" /></p> 
				<hr/>
   				
   				
   				<table>
		   				  				<tr>
		   				  					<td>User</td>
		   				  					<td>Start Date</td>
		   				  				</tr>
		   				  			<% foreach( TestProject.Reservation reservation in (ViewData["Reservations"] as List<TestProject.Reservation> )){%>
		   				  				<tr>
		   				  					<% TestProject.User user = new TestProject.User(reservation.user_ID); %>
		   				  					<td><%= Html.Encode(user.username) %></td>
		   				  					<td><%= Html.Encode(reservation.start) %></td>
		   				  				</tr>
		   				  			<% } %>
		   				  			</table>
   				
   				 <% TestProject.Book book = ViewData["Book"] as TestProject.Book; %>
   				<p>Call Number:	<%= Html.Encode(ViewData["callNo"]) %></p>
   				<p>ISBN:	<%= Html.Encode(book.isbn) %></p>
   				<p>Title:	<%= Html.Encode(book.title) %></p>
   				<p>Author:	<%= Html.Encode(book.author) %></p>
   				<p>Author:	<%= Html.Encode(book.publisher) %></p>
			
			
   			</div>
 			<p style="display:none;" id="loan_range"><%= Html.Encode(ViewData["LoanRange"]) %></p>
   				<input type="hidden" id="copy_id" value="<%= Html.Encode(ViewData["copy_ID"]) %>" />
 </asp:Content>